<template>
  <!--使用验证记录-->
  <div class="jilu">
    <div class="search">
      <wv-cell
        title=""
        :value="startTime"
        is-link
        @click="openPicker('startDatePicker')"
      />
      <wv-datetime-picker
        type="date"
        ref="startDatePicker"
        :endDate="startDate"
        v-model="beginDate"
        @confirm="onConfirmStartDate"
      />
      <div class="line"></div>
      <wv-cell
        title=""
        :value="endTime"
        is-link
        @click="openPicker('endDatePicker')"
      />
      <wv-datetime-picker
        type="date"
        ref="endDatePicker"
        :endDate="endDate"
        v-model="finshDate"
        @confirm="onConfirmEndTime"
      />
    </div>

    <div class="page-infinite-wrapper" ref="wrapper" :style="{ height: wrapperHeight + 'px' }">
      <wv-group
        v-infinite-scroll="getList"
        infinite-scroll-disabled="loading"
        infinite-scroll-distance="10"
      >
        <wv-panel class="lists">
          <wv-media-box thumb="" v-for="(item,index) in list" :title="item.serverName"
                        :description="'登录账号：'+item.accountName" :key="index" type="text">
            <ul class="weui-media-box__info" slot="box_ft">
              <li v-if="item.checkType==1 || item.checkType==3">会员姓名：{{item.userName}}</li>
              <li v-if="item.checkType==1 || item.checkType==3">会员手机号：{{item.mobile}} <wv-button type="default" :mini="true" class="lookdetail" @click="goReduceCheck(item)">核验减录</wv-button></li>
              <li>{{item.createDate}} <span>×{{item.useNum}}</span></li>
            </ul>
          </wv-media-box>
        </wv-panel>
      </wv-group>
    </div>
    <div class="model" v-show="isVisible">
      <div class="bg"></div>
      <div class="modelContent">
        <img src="../../assets/close.png" alt="" width="15" @click="isVisible=false">
        请确认选择减录的记录是否正确?。
        <p class="btn">
          <button @click="submitInfo()">确定</button>
          <button @click="isVisible=false">取消</button>
        </p>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import {employeeCheckRecordList,reduceCheckDataSub} from '../../../test/unit/http'

  export default {
    name: '',
    props: {},
    data() {
      return {
        startDate: new Date(),
        endDate: new Date(),
        beginDate: new Date(),
        finshDate: new Date(),
        content: '',
        createDate: '',
        page: 1,
        rows: 10,
        pages: 0,
        list: [],
        totalNum: 0,
        wrapperHeight: 0,
        loading: false,
        isVisible:false,
        checkrecordId:''
      };
    },
    methods: {
      openPicker(ref) {
        this.$refs[ref].open()
      },
      goSearch(content) {
        this.page = 1;
        let params = {
          content: content,
          startTime: this.startTime,
          endTime: this.endTime,
          page: this.page,
          rows: this.rows
        };
        this.getSearchList(params)
      },
      goReduceCheck(checkrecord){
        this.isVisible=true;
        this.checkrecordId=checkrecord.checkrecordId
      },
      submitInfo(){
        reduceCheckDataSub({checkrecordId:this.checkrecordId}).then(res => {
          console.log(res);
          if (res.code == 100) {
            this.$router.push({path: 'addchecksuccess'});
          } else {
            Toast.fail(res.info)
          }
        })
      },
      getList() {
        this.loading = true;
        let params = {
          content: this.content,
          startTime: this.startTime,
          endTime: this.endTime,
          page: this.page,
          rows: this.rows
        };
        let accountGoodsId=this.$route.query.accountGoodsId;
        if(!this.$myUtils.isNull(accountGoodsId)){
          params['accountGoodsId']=accountGoodsId;
        }
        employeeCheckRecordList(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            let data = res.object;
            let list = data.pqGrid.rows;
            let pages = data.pqGrid.pages;
            this.pages = pages;
            let totalNum = data.totalNum;
            this.totalNum = totalNum;
            if (list.length > 0) {
              this.list = this.list.concat(list);
            }
          }
          if (this.page < this.pages) {
            this.page++;
            this.loading = false
          } else {
            this.loading = true
          }
        }).catch(err => {
          console.log(err);
        });
      },
      getSearchList(params) {
        employeeCheckRecordList(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            this.list = [];
            let data = res.object;
            this.list = data.pqGrid.rows;
            let pages = data.pqGrid.pages;
            this.pages = pages;
            let page = data.pqGrid.page;
            this.page = page;
            let totalNum = data.totalNum;
            this.totalNum = totalNum;
          }
        })
      },
      onConfirmStartDate(value) {
        let message = '';
        if (value !== null && typeof value === 'object') {
          let year = value.getFullYear();
          let month = value.getMonth() + 1;
          if (month < 10) {
            month = '0' + month;
          }
          let date = value.getDate();
          if (date < 10) {
            date = '0' + date;
          }
          message = `${year}-${month}-${date}`
        } else {
          message = value
        }
        this.page = 1;
        let params = {
          content: this.content,
          startTime: this.startTime,
          endTime: this.endTime,
          page: this.page,
          rows: this.rows
        };
        let accountGoodsId=this.$route.query.accountGoodsId;
        if(!this.$myUtils.isNull(accountGoodsId)){
          params['accountGoodsId']=accountGoodsId;
        }
        this.getSearchList(params)
      },
      onConfirmEndTime(value) {
        let message = '';
        if (value !== null && typeof value === 'object') {
          let year = value.getFullYear();
          let month = value.getMonth() + 1;
          if (month < 10) {
            month = '0' + month;
          }
          let date = value.getDate();
          if (date < 10) {
            date = '0' + date;
          }
          message = `${year}-${month}-${date}`
        } else {
          message = value
        }
        this.page = 1;
        let params = {
          content: this.content,
          startTime: this.startTime,
          endTime: this.endTime,
          page: this.page,
          rows: this.rows
        };
        let accountGoodsId=this.$route.query.accountGoodsId;
        if(!this.$myUtils.isNull(accountGoodsId)){
          params['accountGoodsId']=accountGoodsId;
        }
        this.getSearchList(params)
      },
    },
    created() {

    },
    filters: {
      datetimeFilter(value, type) {
        if (value !== null && typeof value === 'object') {
          let year = value.getFullYear();
          let month = value.getMonth() + 1;
          let date = value.getDate();
          let hour = value.getHours();
          let minute = value.getMinutes();
          return type === 'date' ? `${year}/${month}/${date}` : `${year}/${month}/${date} ${hour}:${minute}`
        } else {
          return value
        }
      }
    },
    computed: {
      startTime: {
        get: function () {
          let value = this.beginDate;
          let message = '';
          if (value !== null && typeof value === 'object') {
            let year = value.getFullYear();
            let month = value.getMonth() + 1;
            if (month < 10) {
              month = '0' + month;
            }
            let date = value.getDate();
            if (date < 10) {
              date = '0' + date;
            }
            message = `${year}-${month}-${date}`;
          } else {
            message = value;
          }
          return message;
        },
        set: function (date) {
          return date;
        }
      },
      endTime: {
        get: function () {
          let value = this.finshDate;
          let message = '';
          if (value !== null && typeof value === 'object') {
            let year = value.getFullYear();
            let month = value.getMonth() + 1;
            if (month < 10) {
              month = '0' + month;
            }
            let date = value.getDate();
            if (date < 10) {
              date = '0' + date;
            }
            message = `${year}-${month}-${date}`;
          } else {
            message = value;
          }
          return message;
        },
        set: function (date) {
          return date;
        }
      }
    },
    components: {}
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">

  .weui-panel:before {
    border-top: none;
  }

  .lists {
    text-align: left;

    .weui-media-box__info span {
      position: absolute;
      right: 25px;
      top: 20px;
      font-size: 15px;
      color: #666;
    }

    .weui-media-box__info {
      li {
        color: #666;
        margin-bottom: 15px;
        font-size: 13px;
      }
      li:nth-child(2) {
        font-size: 16px;
        color: #111;
        font-weight: 700;

        span {
          color: #999;
          margin-left: 10px;
          font-size: 12px;
        }

        button {
          float: right;
          display: inline-block;
        }

        .lookdetail {
          background-color: #fff;
          border: 1px solid #f98e3c;
          color: #f98e3c;
        }
      }
      li:last-child {
        font-size: 12px;
        color: #999;
      }
    }
  }

  .bg {
    background-color: rgba(0, 0, 0, 0.3);
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 50px;
  }

  .model .modelContent {
    background-color: #fff;
    border-radius: 8px;
    position: fixed;
    left: 50%;
    top: 50%;
    margin-left: -43%;
    margin-top: -111px;
    z-index: 2;
    padding: 40px 10px 20px;
    width: 80%;
    text-align: left;
    img {
      position: absolute;
      right: 10px;
      top: 10px
    }
    .btn {
      button {
        height: 42px;
        line-height: 42px;
        color: #fff;
        outline: none;
        border: none;
        width: calc(50% - 20px);
        border-radius: 8px;
        margin-top: 25px;
      }
      :last-child {
        background-color: #ccc;
      }
      :first-child {
        background-color: #f98e3c;
        margin-right: 20px;

      }
    }

  }

  .search {
    width: 100%;
    margin: 10px auto;
    display: flex;
  }
</style>
